from PIL import Image
import numpy as np

img = Image.open('./image/test.png').convert('L')
img = img.resize((int(img.width/4), int(img.height/4)))
print('size:', img.size, '\n')
# img.show()

a = np.array(img, dtype='float32')
a = np.trunc(a * 5 / 256) * 0.5
buff = 0
pos_begin = (0, 0)
pos_end = (0, 0)
pos_begin_next = (0, 0)
cnt = 0
shift_flag = False

with open('./Silk.json', 'w') as f:
    with open('./part1.txt', 'r') as p:
        f.write(p.read())
    for i in range(img.height):
        for j in range(img.width):
            x = 4070 + j * 2
            y = 3576.5 + i * 2
            d = a[i, j]
            if d != 0:
                # 图片转焊盘，测试太麻烦，嘉立创不给做
                # f.write('    \"PAD~ELLIPSE~' + str(x) + '~' + str(y) + '~' + str(d) + '~' + str(d) + '~1~~1~0~~0~gge'
                #         + str(i) + str(j) + '~0~~Y~0~~0~' + str(x) + ',' + str(y) + '\",\n')
                # 图片转丝印
                f.write('    \"CIRCLE~' + str(x) + '~' + str(y) + '~' + str(d/4) + '~' + str(d/2) + '~3~gge' + str(i)
                        + str(j) + '~0~~' + '\",\n')
    with open('./part2.txt', 'r') as p:
        f.write(p.read())
